// ---REVIEW POSTING ---//
$(document).ready(function() {

	$("#btn_review_submit").click(function() {
		var base_url = $('body').data('baseurl');


		//alert(base_url);	

		var rev_profile_id = $('#rev_profile_id').val();
		var rev_full_name = $('#rev_full_name').val();
		var rev_email_address = $('#rev_email_address').val();
		var rev_ratting = $('#rev_ratting').val();
		var rev_description = $('#rev_description').val();

		var postData = {
			'rev_profile_id' : rev_profile_id,
			'rev_full_name'	: rev_full_name,
			'rev_email_address'	: rev_email_address,
			'rev_ratting' : rev_ratting,
			'rev_description' : rev_description,
		};

		//alert (postData);
		
	
		var img = base_url + "assets/images/ajax-loader2.gif";
		$('#rev_alert').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "profile/post_review",
			dataType : "json",
			data : postData,
			cache : false,
			success : function(data) {
				$("#rev_alert").html(data.message).fadeIn('slow');
				$('#post_review_form')[0].reset();
			}

		});

	});
});

//---ENQUIRY POSTING ---//
$(document).ready(function() {

	$("#btn_enq_submit").click(function() {
		var base_url = $('body').data('baseurl');
		//var emailID = $('#emailID').val();
		var enqname = $('#enqname').val();
		var enqemail = $('#enqemail').val();
		var enqdescription = $('#enqdescription').val();

		
		var postData = {
			'enqname' : enqname,
			'enqemail' : enqemail,
			'enqdescription' : enqdescription,
		};

		//alert(postData);
		var img = base_url + "assets/images/ajax-loader2.gif";
		$('#msz_alert').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "profile/post_enq/",
			dataType : "json",
			data : postData,
			cache : false,
			success : function(data) {
				$("#msz_alert").html(data.message).fadeIn('slow');
				$('#post_enq_form')[0].reset();
			}

		});

	});
});








//---EMAIL POSTING ---//
$(document).ready(function() {

	$("#btn_contact_submit").click(function() {
		var base_url = $('body').data('baseurl');

		var name = $('#contactname').val();
		var email = $('#contactemail').val();
		var location = $('#location').val();
		var purpose = $('#purpose').val();
		
		var description = $('#description').val();

		// alert (description);
		var postData = {
			'contactname' : name,
			'contactemail' : email,
			'location' : location,
			'purpose' : purpose,
			'description' : description,
		};

		var img = base_url + "assets/images/ajax-loader2.gif";
		$('#contact_alert').html('<img src="' + img + '" />')

		$.ajax({
			type : "POST",
			url : base_url + "member/post_mail",
			dataType : "json",
			data : postData,
			cache : false,
			success : function(data) {
				$("#contact_alert").html(data.message).fadeIn('slow');
				$('#post_contact_form')[0].reset();
			}

		});

	});
});

$(document).ready(function() {
	var base_url = $('body').data('baseurl');

	$("#btn_prod").click(function() {
		if ($('#autocomplete').val() == "") {
			alert("Type Something ...");
			$("#autocomplete").focus();
			return false;
		}
		;
	});

	$('#autocomplete').autocomplete({
		source : base_url + "category/category/autocomplete",
		minLength : 2,
		delay : 10,
		enable : true,
		autoFocus : true,

		focus : function(event, ui) {

			// var r = val(ui.item.value);
			// var my= $(this).val(stripHTML($(this).val());
			// $("#autocomplete").val(ui.item.label);
			// $('#autocomplete').val(stripHTML($("#autocomplete").val(ui.item.label)));

			$("#prod_id").val(ui.item.value);
			return false;
		},
		select : function(event, ui) {
			$("#autocomplete").val(ui.item.label);
			$("#prod_id").val(ui.item.value);
			return false;
		},

	});

});


$(document).ready(function() {
	var base_url = $('body').data('baseurl');

	$("#btn_busin").click(function() {
		if ($('#lawyer_search').val() == "") {
			alert("Type Something ...");
			$("#lawyer_search").focus();
			return false;
		}
		;
	});

	$('#lawyer_search').autocomplete({
		source : base_url + "category/autocomplete/lawyer_search",
		minLength : 2,
		delay : 10,
		enable : true,
		autoFocus : true,

		focus : function(event, ui) {

			// var r = val(ui.item.value);
			// var my= $(this).val(stripHTML($(this).val());
			// $("#autocomplete").val(ui.item.label);
			// $('#autocomplete').val(stripHTML($("#autocomplete").val(ui.item.label)));

			$("#busin_id").val(ui.item.value);
			return false;
		},
		select : function(event, ui) {
			$("#lawyer_search").val(ui.item.label);
			$("#busin_id").val(ui.item.value);
			return false;
		},

	});

});

$(document).ready(function() {
	var base_url = $('body').data('baseurl');
	$('#city_search').autocomplete({
		source : base_url + "category/autocomplete/find_location",
		minLength : 2,
		delay : 10,
		enable : true,
		autoFocus : true,

		select : function(event, ui) {
			$("#city_search").val(ui.item.label);
			$("#city_id").val(ui.item.value);
			return false;
		},

	});

});

$(document).ready(function() {

	var base_url = $('body').data('baseurl');

	$('#loca_search').autocomplete({
		source : base_url + "category/autocomplete/find_location",
		minLength : 2,
		delay : 10,
		enable : true,
		autoFocus : true,

		select : function(event, ui) {
			$("#loca_search").val(ui.item.label);
			$("#loca_id").val(ui.item.value);
			return false;
		},

	});

});






$(document).ready(function() {
	var base_url = $('body').data('baseurl');

	$("#btn_clear").click(function() {

		$.ajax({

			url : base_url + "location/city/clear_location",
			success : function(response) {// response is value returned from
											// php (for your example it's "bye
											// bye"
				document.location.reload();
			}
		});

	});

});

$(function(){
    $('.carousel').carousel({
      interval: 2000
    });
});

$(document).ready(function(){
    $('#state').change(function(){ //any select change on the dropdown with id country trigger this code
        $("#city > option").remove(); //first of all clear select items
        var stateid = $('#state').val();  // here we are taking country id of the selected one.
        //alert(stateid);
         $("#city").removeAttr('disabled');
       
        var base_url = $('body').data('baseurl');
		//alert(base_url);
        
        
        //var base_url = "<?php echo 'HELL'; ?>";
        //alert (base_url);
        
        
        $.ajax({
            type: "POST",
            url: base_url+"location/city/get_cities/"+stateid, //here we are calling our user controller and get_cities method with the country_id
            
            success: function(cities) //we're calling the response json array 'cities'
            {
            	var opt1 = $('<option />'); // here we're creating a new select option with for each city
                opt1.val(0);
                opt1.text("--Select City--");
                $('#city').append(opt1); //here we will append these new select options to a dropdown with the id 'cities'
                
            	
                $.each(cities,function(id,city) //here we're doing a foeach loop round each city with id as the key and city as the value
                {
                	var opt = $('<option />'); // here we're creating a new select option with for each city
                    opt.val(id);
                    opt.text(city);
                    $('#city').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                });
            }

        });

    });
});

$(document).ready(function(){
	$('#mymap1').show();
	var lat = $('#lat').val();
	var longg = $('#long').val();
	//alert (longg);

	var latlng = new google.maps.LatLng(lat,longg);
	    var map = new google.maps.Map(document.getElementById('map1'), {
	        center: latlng,
	        zoom: 14,
	        mapTypeId: google.maps.MapTypeId.ROADMAP
	    });
	    var marker = new google.maps.Marker({
	        position: latlng,
	        map: map,
	        title: 'Set lat/lon values for this property',
	        draggable: true
	    });
		 google.maps.event.addListener(marker, 'dragend', function(a) {
	        console.log(a);
	              
			document.getElementById('lat').value = a.latLng.lat().toFixed(4);
			document.getElementById('long').value = a.latLng.lng().toFixed(4);
	        document.getElementsByTagName('body')[0].appendChild(div);
	    });
		
	});

function getlattlong() {
	$('#mymap1').show();
	
	var geocoder = new google.maps.Geocoder();
	
	var street=$("#street_address1").val();
	//var street2=$("#street_address2").val();
	//var country=$("#country option:selected").html();
	var state=$("#statediv option:selected").html();
	var city=$("#citydiv option:selected").html();
	
	//var address=country+','+state+','+city+','+street;
	var address=street+','+city+','+state;
	
	
	geocoder.geocode( { 'address': address}, function(results, status) {

	if (status == google.maps.GeocoderStatus.OK) {
    var latitude = results[0].geometry.location.lat();
	var longitude = results[0].geometry.location.lng();
	document.getElementById('lat').value=latitude;
	document.getElementById('long').value=longitude;
    } 

	
    var latlng = new google.maps.LatLng(latitude,longitude);
    var map = new google.maps.Map(document.getElementById('map1'), {
        center: latlng,
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Set lat/lon values for this property',
        draggable: true
    });
    google.maps.event.addListener(marker, 'dragend', function(a) {
        console.log(a);
       
        
		document.getElementById('lat').value = a.latLng.lat().toFixed(4);
		document.getElementById('long').value = a.latLng.lng().toFixed(4);
        document.getElementsByTagName('body')[0].appendChild(div);
    });
	}); 
};


function getlatlong() {
	$('#mymap').show();
	var geocoder = new google.maps.Geocoder();
	
	var street=$("#street_address1").val();
	//var street2=$("#street_address2").val();
	//var country=$("#country option:selected").html();
	var state=$("#statediv option:selected").html();
	var city=$("#citydiv option:selected").html();
	
	//var address=country+','+state+','+city+','+street;
	var address=street+','+city+','+state;
	
	geocoder.geocode( { 'address': address}, function(results, status) {

	if (status == google.maps.GeocoderStatus.OK) {
    var latitude = results[0].geometry.location.lat();
	var longitude = results[0].geometry.location.lng();
	document.getElementById('lat').value=latitude;
	document.getElementById('long').value=longitude;
    } 

	
    var latlng = new google.maps.LatLng(latitude,longitude);
    var map = new google.maps.Map(document.getElementById('map'), {
        center: latlng,
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        title: 'Set lat/lon values for this property',
        draggable: true
    });
    google.maps.event.addListener(marker, 'dragend', function(a) {
        console.log(a);
       
        
		document.getElementById('lat').value = a.latLng.lat().toFixed(4);
		document.getElementById('long').value = a.latLng.lng().toFixed(4);
        document.getElementsByTagName('body')[0].appendChild(div);
    });
	}); 
};		



